<%@page import="DB.DBProvider"%>
<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<%@ page import="java.util.*, java.io.*,java.sql.ResultSet" %>
<% 
   String user = (String)request.getSession().getAttribute("username");
   String admin = (String)request.getSession().getAttribute("administrator");
   Properties p = new Properties();
   p.load(getServletContext().getResourceAsStream("/WEB-INF/config"));
   ResultSet res;
  /*
   String Course_names ="";
   ResultSet res = (new DBProvider(p)).GetCoursesNames();
   if(res.next())
   {
	   Course_names=res.getString(1);
   
   }
   while(res.next()) 
   {
	   Course_names=Course_names+" "+res.getString(1);
	   
   } */
   
	 
%>


<script type="text/javascript">
	$(document).ready(function()
		{	
		  var flag = 0;
		  
		  function loadres()
		  {
			var q = $("#keyword").serialize();
			var g = $("#Groupnum").val();
			var c = $("#Creditpoints").val();
			var av;
			
			if($("#available").is(':checked'))
			{
				av = "yes";
			}
			else
			{
			av = "no";
			}
				
			$('#results').load("/Calendars/searchres.jsp?" + q + "&gro=" + g + "&cre=" + c+"&ava="+ av,function(response, status, xhr) {
				  if (status == "error") {
					    var msg = "Sorry but there was an error: ";
					    $("#page").html("<br />" +"<h1>" + msg + xhr.status + " " + xhr.statusText +"</h1>" );
					  }
					});
		    	
		   }
		  
		    $('.onchange').keyup(function() 
		    { 
		    	loadres();
		    	
		    });
		    
		    $("#available").change(function() 
			{ 
		    	loadres();
			});
		    
		  	$('#search').click(function()
			{
				$("span").find("span:last").remove();
				flag++;
				loadres();
				
			});	
			
			$('#search').hover(function(){
				
				if(flag == 0)
				{
					$("span").append($("<span class='blue'>Empty search to get all courses </span>"));

				}
				
			} , 
			  function () {
				if(flag == 0)
				{
			    	$("span").find("span:last").remove();
			    }
			  }
			);
		});
	
	$( document ).ajaxStart( function() {
		$( '#spinner' ).show();
	}).ajaxStop( function() {
		$( '#spinner' ).hide();
	});
</script>
	
	<div id="firsthead" class="post">
		<h1 class="title">Search for a course</h1>
		
		<center>
		
		<table border="0" width="60%">
		<tr>
		<td width="40%" height="10%">
		<h2> Keywords:</h2>
		</td>
		
		<td width="20%">
		</td>
		
		<td width="40%" height="10%">
		<h2>Filters:</h2>
		</td>
		</tr>

		<tr>
		<td width="40%" height="90%">
		<input class="onchange" id="keyword" name="que"/>
		<br />
		<button id="search">
		  Search
		</button>
		</td>
		
		<td width="20%">
		</td>
		
		<td width="40%" height="90%">
		<div align="right">
		<b>Group number : </b><input class="onchange" id="Groupnum"  value="" size="1"  align="right"/> 
		<br />
		<b>Credit points : </b><input class="onchange" id="Creditpoints"  value="" size="1"  align="right"/>
		<br />
		<b>available courses : </b><input type="checkbox" value="yes" id="available"  value="" size="1"  align="right"/>
		</div>
		</td>
		</tr>
		
		</table>
		<p>
		<span></span>
		</p>
		<center>
		<div id="spinner"><img src="style/spinner.gif"/></div>
		</center>
		
		<div id="results">
		
		</div>
		
		<div id="results">
		
		</div>
		
		</center>

		
	</div>		
